var amapFile = require('../../libs/amap-wx.130.js');

var markersData = [];
Page({
  data: {
    markers: [],
    latitude: '',
    longitude: '',
    textData: {}
  },
  makertap: function(e) {
    var id = e.markerId;
    var that = this;
    that.showMarkerInfo(markersData,id);
    that.changeMarkerColor(markersData,id);
  },
  onLoad: function() {
    var that = this;
    var myAmapFun = new amapFile.AMapWX({key:'038c54183637f97bf87484c0ce1c7b01'});
    wx.request({
      url: 'http://localhost:3000/spots/getgone',
      method: 'GET',
      data: {
        userid:getApp().globalData.user.id
      },
      success:res=>{
        markersData=res.data
        console.log('look',markersData)
        for(let i =0;i<markersData.length;i++){
          markersData[i].id=i
        }
        that.setData({
          markers: markersData
        });
        that.setData({
          latitude: markersData[0].latitude
        });
        that.setData({
          longitude: markersData[0].longitude
        });
        that.showMarkerInfo(markersData,0);
      },
      fail:err=>{
        
      }
    })
        
  },
  showMarkerInfo: function(data,i){
    console.log(data)
    var that = this;
    that.setData({
      textData: {
        name: data[i].name,
        desc: data[i].timer.join('；')+'去过'
      }
    });
  },
  changeMarkerColor: function(data,i){
    var that = this;
    var markers = [];
    for(var j = 0; j < data.length; j++){
      // if(j==i){
      //   data[j].iconPath = "选中 marker 图标的相对路径"; //如：..­/..­/img/marker_checked.png
      // }else{
      //   data[j].iconPath = "未选中 marker 图标的相对路径"; //如：..­/..­/img/marker.png
      // }
      markers.push(data[j]);
    }
    that.setData({
      markers: markers
    });
  },
  makertap(e){
    console.log(e)
    var id = e.markerId;
    var that = this;
    that.showMarkerInfo(markersData,id);
    that.changeMarkerColor(markersData,id);
  }

})



